/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2024-11-23
 * Time: 12:47
 */
public class test1 {
    /*
    NewCoder  NC78 反转链表
    给定一个单链表的头结点pHead(该头节点是有值的，比如在下图，它的val是1)，长度为n，反转该链表后，返回新链表的表头。

     */

    public ListNode ReverseList (ListNode head) {
        // write code here
        if(head==null || head.next==null){
            return head;
        }
        ListNode newHead =null;
        while(head!=null){
            ListNode cur = head.next;
            head.next=newHead;
            newHead = head;
            head = cur;
        }
        return newHead;
    }


    public class ListNode {
    int val;
    ListNode next = null;
    public ListNode(int val) {
      this.val = val;
    }
  }
}
